extends NodeState

# 头球射门

const BEGIN_HEIGHT: float = 0.1
const BEGIN_HEIGHT_VELOCITY: float = 1.5


var player: Player:
	get:
		return state_matchine.root as Player



func _on_process(delta : float) -> void:
	_process_header(delta)



func _on_enter(_data: NodeStateData) -> void:
	player.height = BEGIN_HEIGHT
	player.height_velocity = BEGIN_HEIGHT_VELOCITY

	_process_animation()
	# 头球时使用球当前的高度射出
	player.ball.shoot(player.shooting_power * player.header_power_factor,
						player.shooting_power * player.header_power_factor,
						player.offensive_goal.get_random_target_direction(player),
						player.ball.height)


func _on_exit() -> void:
	pass



func _process_header(delta : float):
	player.player_sprite.position.y = -player.height

	if player.height <= 0.0:
		player.height = 0.0
		player.height_velocity = 0.0
		transition_state(Player.STATE_RECOVERING)
		return

	player.height_velocity -= GlobalConstants.PLAYER_GRAVITY * delta
	player.height += player.height_velocity



func _process_animation():
	player.animation_player.play(Player.ANIMATION_HEADER)
